<html>
 <head>
  <meta charset="utf-8"/>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport"/>
  <title>
   主题：windows下 LyX+knitr 编译不成功  | 数螺 | NAUT IDEA
  </title>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" rel="stylesheet"/>
  <link href="http://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
  <style type="text/css">
   #xmain img {
                  max-width: 100%;
                  display: block;
                  margin-top: 10px;
                  margin-bottom: 10px;
                }

                #xmain p {
                    line-height:150%;
                    font-size: 16px;
                    margin-top: 20px;
                }

                #xmain h2 {
                    font-size: 24px;
                }

                #xmain h3 {
                    font-size: 20px;
                }

                #xmain h4 {
                    font-size: 18px;
                }


                .header {
	           background-color: #0099ff;
	           color: #ffffff;
	           margin-bottom: 20px;
	        }

	        .header p {
                  margin: 0px;
                  padding: 10px 0;
                  display: inline-block;  
                  vertical-align: middle;
                  font-size: 16px;
               }

               .header a {
                 color: white;
               }

              .header img {
                 height: 25px;
              }
  </style>
  <script src="http://cdn.bootcss.com/jquery/3.0.0/jquery.min.js">
  </script>
  <script src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript">
   MathJax.Hub.Config({elements: ["bbpress-forums"]});
  </script>
  <script src="http://nautstatic-10007657.file.myqcloud.com/static/css/readability.min.js" type="text/javascript">
  </script>
  <script type="text/javascript">
   $(document).ready(function() {
                 var loc = document.location;
                 var uri = {
                  spec: "http://cos.name/cn/topic/109287/",
                  host: "http://cos.name",
                  prePath: "http://cos.name",
                  scheme: "http",
                  pathBase: "http://cos.name/"
                 };
    
                 var documentClone = document.cloneNode(true);
                 var article = new Readability(uri, documentClone).parse();
     
                 document.getElementById("xmain").innerHTML = article.content;
                });
  </script>
  <!-- 1466441151: Accept with keywords: (title(0.333333333333):编译,主题,论坛, topn(0.166666666667):帖子,编译,会员,图形,目录,文件,用户名,结果,参数,情况,格式,编码,中文,字节,标题,问题,密码,普通,乱码,你好,字符,功能,代码,主题,总计,绘图,论坛,字体,事实证明,讨论区).-->
 </head>
 <body class="topic bbpress single single-topic postid-109287 single-author sidebar" onload="">
  <div class="header">
   <div class="container">
    <div class="row">
     <div class="col-xs-6 col-sm-6 text-left">
      <a href="/databee">
       <img src="http://nautidea-10007657.cos.myqcloud.com/logo_white.png"/>
      </a>
      <a href="/databee">
       <p>
        数螺
       </p>
      </a>
     </div>
     <div class="hidden-xs col-sm-6 text-right">
      <p>
       致力于数据科学的推广和知识传播
      </p>
     </div>
    </div>
   </div>
  </div>
  <div class="container text-center">
   <h1>
    主题：windows下 LyX+knitr 编译不成功
   </h1>
  </div>
  <div class="container" id="xmain">
   <div class="hfeed site" id="page">
    <header class="site-header" id="masthead" role="banner">
     <div id="cos-logo">
      <a href="http://cos.name/cn">
       <img src="http://cos.name/cn/wp-content/themes/COS-forest/images/headers/cos-logo.png"/>
      </a>
     </div>
     <div class="navbar" id="navbar">
      <nav class="navigation main-navigation" id="site-navigation" role="navigation">
       <h3 class="menu-toggle">
        菜单
       </h3>
       <div class="menu-%e8%8f%9c%e5%8d%951-container">
        <ul class="nav-menu" id="menu-%e8%8f%9c%e5%8d%951">
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-home menu-item-407772" id="menu-item-407772">
          <a href="http://cos.name/cn/">
           论坛首页
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407773" id="menu-item-407773">
          <a href="http://cos.name/cn/forums/">
           讨论区
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407774" id="menu-item-407774">
          <a href="http://cos.name/cn/wp-login.php?action=register">
           注册
          </a>
         </li>
         <li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-407819" id="menu-item-407819">
          <a href="http://cos.name/">
           主站
          </a>
         </li>
        </ul>
       </div>
      </nav>
      <!-- #site-navigation -->
     </div>
     <!-- #navbar -->
    </header>
    <!-- #masthead -->
    <div class="site-main" id="main">
     <div class="content-area" id="primary">
      <div class="site-content" id="content" role="main">
       <article class="post-109287 topic type-topic status-publish hentry" id="post-109287">
        <header class="entry-header">
         <h1 class="entry-title">
          windows下 LyX+knitr 编译不成功
         </h1>
        </header>
        <!-- .entry-header -->
        <div class="entry-content">
         <div id="bbpress-forums">
          <div class="bbp-breadcrumb">
           <p>
            <a class="bbp-breadcrumb-home" href="http://cos.name/cn/">
             COS论坛 | 统计之都
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-root" href="http://cos.name/cn/forums/">
             讨论区
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-forum" href="http://cos.name/cn/forum/software/">
             软件应用
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <a class="bbp-breadcrumb-forum" href="http://cos.name/cn/forum/software/r-language/">
             S-Plus &amp; R语言
            </a>
            <span class="bbp-breadcrumb-sep">
             ›
            </span>
            <span class="bbp-breadcrumb-current">
             windows下 LyX+knitr 编译不成功
            </span>
           </p>
          </div>
          <div class="bbp-template-notice info">
           <p class="bbp-topic-description">
            该主题包含 27 条回复，7个帖子，最后由
            <a class="bbp-author-avatar" href="http://cos.name/cn/profile/109572/" rel="nofollow" title="查看ywh19860616的档案">
             <img src="http://sdn.geekzu.org/avatar/8599115e910c111374c57034b9f33bda?s=14&amp;d=monsterid&amp;r=g"/>
            </a>
            <a class="bbp-author-name" href="http://cos.name/cn/profile/109572/" rel="nofollow" title="查看ywh19860616的档案">
             ywh19860616
            </a>
            在
            <a href="http://cos.name/cn/topic/109287/page/2/#post-381172" title="回复：windows下 LyX+knitr 编译不成功">
             2 年, 6 月 之前
            </a>
            更新。
           </p>
          </div>
          <div class="bbp-pagination">
           <div class="bbp-pagination-count">
            查看 15 个帖子 - 1 到 15（总计 28 个）
           </div>
           <div class="bbp-pagination-links">
            <span class="page-numbers current">
             1
            </span>
            <a class="page-numbers" href="http://cos.name/cn/topic/109287/page/2/">
             2
            </a>
            <a class="next page-numbers" href="http://cos.name/cn/topic/109287/page/2/">
             →
            </a>
           </div>
          </div>
          <ul class="forums bbp-replies" id="topic-109287-replies">
           <li class="bbp-header">
            <div class="bbp-reply-author">
             作者
            </div>
            <!-- .bbp-reply-author -->
            <div class="bbp-reply-content">
             帖子
            </div>
            <!-- .bbp-reply-content -->
           </li>
           <!-- .bbp-header -->
           <li class="bbp-body">
            <div class="bbp-reply-header" id="post-109287">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月1日 上午3:46
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-109287">
               1 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-109287 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-1 user-id-42042 topic-author post-109287 topic type-topic status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               <img src="http://sdn.geekzu.org/avatar/593454e1c6fe5aa47e56a03680a71371?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               kelffon
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               我是完全按照老大的视频（http://www.screenr.com/SvL8）来设置的，可还是不行！以下是log ，谁帮我诊断一下！
              </p>
              <p>
               This is XeTeX, Version 3.1415926-2.3-0.9997.5 (MiKTeX 2.9) (preloaded format=xelatex 2013.1.31)  1 FEB 2013 11:44
               <br/>
               entering extended mode
               <br/>
               **LyX-knitr.tex
              </p>
              <p>
               (“C:\Documents and Settings\wgh2wxy\Local Settings\Temp\lyx_tmpdir.Hp3572\lyx_t
               <br/>
               mpbuf2\LyX-knitr.tex”
               <br/>
               LaTeX2e &lt;2011/06/27&gt;
               <br/>
               ….
               <br/>
               [s:11]Runaway argument?
               <br/>
               {璋㈢泭杈墋
               <br/>
               ! Paragraph ended before \author was complete.
               <br/>
               &lt;to be read again&gt;
               <br/>
               \par
               <br/>
               l.70
              </p>
              <p>
               I suspect you’ve forgotten a `}’, causing me to apply this
               <br/>
               control sequence to too much text. How can we recover?
               <br/>
               My plan is to forget the whole thing and hope for the best.
              </p>
              <p>
               )[s:11]
               <br/>
               [s:11]Runaway argument?
               <br/>
               {2012骞
               <br/>
               ! File ended while scanning use of \date.
               <br/>
               &lt;inserted text&gt;
               <br/>
               \par
               <br/>
               &lt;*&gt; LyX-knitr.tex
              </p>
              <p>
               I suspect you have forgotten a `}’, causing me
               <br/>
               to read past where you wanted me to stop.
               <br/>
               I’ll try to recover; but if the error is serious,
               <br/>
               you’d better type
               <code>
                E' or
               </code>
               X’ now and fix your file.
              </p>
              <p>
               ! Emergency stop.
               <br/>
               &lt;*&gt; LyX-knitr.tex
              </p>
              <p>
               *** (job aborted, no legal \end found)[s:11]
              </p>
              <p>
               Here is how much of TeX’s memory you used:
               <br/>
               15078 strings out of 429156
               <br/>
               317527 string characters out of 3171140
               <br/>
               310215 words of memory out of 3000000
               <br/>
               18175 multiletter control sequences out of 15000+200000
               <br/>
               6678 words of font info for 21 fonts, out of 3000000 for 9000
               <br/>
               786 hyphenation exceptions out of 8191
               <br/>
               57i,0n,35p,878b,150s stack positions out of 5000i,500n,10000p,200000b,50000s
               <br/>
               No pages of output.
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342306">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月1日 上午3:51
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342306">
               2 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342306 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-2 user-id-42042 topic-author post-342306 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               <img src="http://sdn.geekzu.org/avatar/593454e1c6fe5aa47e56a03680a71371?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               kelffon
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               似乎问题就出在里面我做了图标的地方
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342308">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月1日 上午4:02
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342308">
               3 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342308 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-3 user-id-42042 topic-author post-342308 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               <img src="http://sdn.geekzu.org/avatar/593454e1c6fe5aa47e56a03680a71371?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/42042/" rel="nofollow" title="查看kelffon的档案">
               kelffon
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               我自己发现了三个问题
               <br/>
               (1)\author{璋㈢泭杈墋  少了”}”    与log提示吻合
               <br/>
               (2)\date{2012骞  少了”}”    也与log提示吻合
               <br/>
               (3)是不是也少了\end{document}
              </p>
              <p>
               该怎么解决？
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342339">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月2日 上午5:08
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342339">
               4 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342339 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-4 user-id-1 post-342339 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               <img src="http://sdn.geekzu.org/avatar/1022d8e6ebc94e8f6bca9a86cebe312a?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               谢益辉
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               多半是编码问题。
              </p>
              <p>
               1. 更新R包，参见
               <a href="https://github.com/yihui/knitr/blob/master/FAQ.md" rel="nofollow">
                https://github.com/yihui/knitr/blob/master/FAQ.md
               </a>
               <br/>
               2. 更新LyX到最新版本，然后用这个文件替代安装目录下的同名文件：
               <a href="https://raw.github.com/yihui/lyx/master/scripts/lyxknitr.R" rel="nofollow">
                https://raw.github.com/yihui/lyx/master/scripts/lyxknitr.R
               </a>
               你没说装在哪儿，只能连蒙带猜在C盘某个目录下了。等LyX 2.0.6出来就不存在这一步了，参见
               <a href="http://www.lyx.org/trac/ticket/8504" rel="nofollow">
                http://www.lyx.org/trac/ticket/8504
               </a>
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342368">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月3日 上午10:49
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342368">
               5 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342368 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-5 user-id-375409 post-342368 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               <img src="http://sdn.geekzu.org/avatar/79fd3c1e1ddfb0a43ba2d937049e5513?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               zggjtsgzczh
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第4楼 的 谢益辉：
               <br/>
               修复了Windows下使用Rstudio通过Rsweave编译Rnw文件导出pdf文件过程中，插入的R代码中不能使用中文的问题。同时出现一个问题，无法在生成图形的标题中使用中文。代码如下：
              </p>
              <p>
              </p>
              <pre class="highlight ">\documentclass[UTF8,10pt]{ctexart}
\usepackage[a4paper,%%textwidth=129mm,textheight=185mm, %%193-8
text={160mm,260mm},centering]{geometry}
\pagestyle{empty}
\begin{document}
\title{使用ggplot2测试中文支持情况}
\abstract{
abc 测试中文,测试中文的目的在于是否能够在Rstudio的knirt中正常编译含有中文的字符，不会出现乱码的情况，事实证明，需要在代码开始设置UTF-8字符编码格式才可以正常使用中文。}
&lt;&lt;setup, include=FALSE&gt;&gt;=
options(device = function(file, width = 2, height = 2, ...) {
  cairo_pdf(tempfile(), width = width, height = height, ...)
})
pdf.options(encoding="GB2312")
@
&lt;&lt;cyrillic, dev='cairo_pdf'&gt;&gt;=
library(ggplot2)
ti &lt;- "中文"
p &lt;- ggplot(data=mpg,mapping=aes(x=cty,y=hwy))
p + geom_point() + opts(title="测试")
@
\textbf{ggplot}这里主要测试中文是否能够正常支持的功能。
&lt;&lt;fig.width=5, fig.height=3, message=FALSE, tidy=FALSE, fig.align="center"&gt;&gt;=
y &lt;- c("PRC","USA","UK","FR")
x &lt;- c("中国","美国","英国","法国")
y
x
@
\end{document}
</pre>
              <p>
               问题就出在了在ggplot中使用opts的title参数设置中文，会在生成的pdf文件中显示错误，且无法在所生成的图形标题中正常显示中文，具体结果运行代码可知。
              </p>
              <p>
               OS:win
               <br/>
               R :R i386 2.15.2
               <br/>
               Rstudio:0.97.310
               <br/>
               LyX:2.0.4
               <br/>
               Knitr:1.0.5
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342382">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月3日 下午5:49
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342382">
               6 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342382 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-6 user-id-1 post-342382 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               <img src="http://sdn.geekzu.org/avatar/1022d8e6ebc94e8f6bca9a86cebe312a?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               谢益辉
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               这是个一言难尽的问题。搜Encoding：
               <a href="http://yihui.name/knitr/demo/graphics/" rel="nofollow">
                http://yihui.name/knitr/demo/graphics/
               </a>
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342384">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月3日 下午7:16
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342384">
               7 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342384 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-7 user-id-375409 post-342384 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               <img src="http://sdn.geekzu.org/avatar/79fd3c1e1ddfb0a43ba2d937049e5513?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               zggjtsgzczh
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               了解，那我就还是用E文吧。上面的代码我重排了一下，使用了pdf.options()函数，并设置encoding为gb2132。效果相对开始时有了一定的变化，标题乱码从……….变为了口口了，[s:19]
              </p>
              <p>
               至于utf8，试了一下不是太好。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342389">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月4日 上午12:30
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342389">
               8 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342389 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-8 user-id-1 post-342389 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               <img src="http://sdn.geekzu.org/avatar/1022d8e6ebc94e8f6bca9a86cebe312a?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               谢益辉
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               pdf()设备的字体和编码设置会让人崩溃的，遇到多字节的情况，建议用我上面链接里说的cairo_pdf()试试，它对多字节字符相对友好一些。
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342411">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月4日 上午8:19
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342411">
               9 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342411 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-9 user-id-375409 post-342411 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               <img src="http://sdn.geekzu.org/avatar/79fd3c1e1ddfb0a43ba2d937049e5513?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               zggjtsgzczh
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第8楼 的 谢益辉：
               <br/>
               我尝试一下，有结果再回复。[s:13]
              </p>
              <p>
               ===================
               <br/>
               已经有结果了，基本功能已经可以正常使用。效果请在Rstudio中使用Knitr键入如下代码到Rnw文件中，并生成pdf。pdf中文、R code中文、code output中文、ggplot2 &amp; plot绘图使用中文字符均已初步解决。
              </p>
              <p>
              </p>
              <pre class="highlight ">\documentclass[UTF8,10pt]{ctexart}
\usepackage[a4paper,%%textwidth=129mm,textheight=185mm, %%193-8
text={160mm,260mm},centering]{geometry}
\pagestyle{empty}
\begin{document}
\title{使用ggplot2测试中文支持情况}
\maketitle
\abstract{
abc 测试中文,测试中文的目的在于是否能够在Rstudio的knirt中正常编译含有中文的字符，不会出现乱码的情况，事实证明，需要在代码开始设置UTF-8字符编码格式才可以正常使用中文。}
&lt;&lt;setup, include=FALSE&gt;&gt;=
options(device = function(file, width = 2, height = 2, ...) {
  cairo_pdf(tempfile(), width = width, height = height, ...)
})
pdf.options(family = "GB1")
@
\textbf{plot}这里主要测试plot是否支持中文功能。
&lt;&lt;fig.width=5, fig.height=3, message=FALSE, tidy=FALSE, fig.align="center"&gt;&gt;=
library(ggplot2)
ti &lt;- "中文"
plot(c(1:10), main = "这是中文的标题", xlab = "X轴也是中文的",ylab="Y轴呢？")
@
\textbf{ggplot}这里主要测试ggplot的中文是否能够正常支持。
&lt;&lt;fig.width=5, fig.height=3, message=FALSE, tidy=TRUE, fig.align="center"&gt;&gt;=
y &lt;- c("PRC","USA","UK","FR")
x &lt;- c("中国","美国","英国","法国")
p &lt;- ggplot(data=mpg,mapping=aes(x=cty,y=hwy))
p + geom_point() + opts(title="ggplot的中文标题是这样子",plot.title=theme_text(face="bold",size=10,hjust=0.5,vjust=2,colour="black")) + xlab("测试X轴") + ylab("测试Y轴")
#dev.off()
#dev.off()
@
\textbf{}下面我们测试是否能够在代码执行中正常输出中文；输出结果如下
&lt;&lt;&gt;&gt;=
y
x
@
\textbf{ggplot}我这里中文功能的支持主要使用的是pdf.options(family = "GB1")参数；如果你对ggplot或plot所绘制的图形有细节调整需求，比如：调整标题字体等，可使用各自的绘图参数调整即可，就像文中ggplot代码中的opts参数所列；
\end{document}
</pre>
              <p>
              </p>
              <p>
               每个人的系统不同，可能会出现不同的字体簇设置。我这里主要参考了一下一些说明:
               <br/>
               <a class="d4pbbc-url" href="http://yihui.name/knitr/demo/graphics/" rel="nofollow" target="_blank">
                http://yihui.name/knitr/demo/graphics/
               </a>
               <br/>
               <a class="d4pbbc-url" href="https://github.com/yihui/knitr/issues/172" rel="nofollow" target="_blank">
                https://github.com/yihui/knitr/issues/172
               </a>
               <br/>
               <a class="d4pbbc-url" href="https://github.com/yihui/knitr/issues/436" rel="nofollow" target="_blank">
                https://github.com/yihui/knitr/issues/436
               </a>
               <br/>
               以及
               <br/>
               <a class="d4pbbc-url" href="http://yihui.name/cn/2010/02/misc-issues-in-latex-lyx-r-sweave-pgfsweave/" rel="nofollow" target="_blank">
                http://yihui.name/cn/2010/02/misc-issues-in-latex-lyx-r-sweave-pgfsweave/
               </a>
              </p>
              <p>
               OS:win
               <br/>
               R version:2.15.0
               <br/>
               R Studio:0.97.310
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342435">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月5日 下午3:59
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342435">
               10 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342435 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-10 user-id-375409 post-342435 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               <img src="http://sdn.geekzu.org/avatar/79fd3c1e1ddfb0a43ba2d937049e5513?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               zggjtsgzczh
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               最后说明一下，R调用LyX编译不能显示中文的确不是Knitr的Bug。[s:17]
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-342438">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年2月5日 下午8:40
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-342438">
               11 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-342438 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-11 user-id-1 post-342438 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               <img src="http://sdn.geekzu.org/avatar/1022d8e6ebc94e8f6bca9a86cebe312a?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/1/" rel="nofollow" title="查看谢益辉的档案">
               谢益辉
              </a>
              <br/>
              <div class="bbp-author-role">
               站长
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               很好的总结，谢谢！不过又要逼着我更新旧日志文章……
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-364655">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年10月8日 上午2:03
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-364655">
               12 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-364655 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-12 user-id-379150 post-364655 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               <img src="http://sdn.geekzu.org/avatar/cdccd546d54980b6c3c4256c21cd8dc7?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               god123
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第9楼 的 zggjtsgzczh：
               <br/>
               你好，我复制了你的代码，执行后我这里报错
               <br/>
               19 &lt;&lt;fig.width=5, fig.height=3, message=FALSE, tidy=FALSE, fig.align=”center”&gt;&gt;=
               <br/>
               20 library(ggplot2)
               <br/>
               21 ti &lt;- “中文”
               <br/>
               22 plot(c(1:10), main = “这是中文的标题”, xlab = “X轴也是中文的”,ylab=”Y轴呢？”)
               <br/>
               23 @
              </p>
              <p>
               Quitting from lines 19-22 (11.Rnw)
               <br/>
               Error in grepl(“\n”, lines, fixed = TRUE) :
               <br/>
               invalid multibyte string at ‘&lt;83&gt;”‘
               <br/>
               请问是什么原因，谢谢 ，是RSTUDIO配置问题还是其他原因？
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-364683">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年10月8日 上午6:17
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-364683">
               13 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-364683 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-13 user-id-375409 post-364683 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               <img src="http://sdn.geekzu.org/avatar/79fd3c1e1ddfb0a43ba2d937049e5513?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/375409/" rel="nofollow" title="查看zggjtsgzczh的档案">
               zggjtsgzczh
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第12楼 的 god123：
               <br/>
               升级R和RStudio至最新版。可解决中文问题。不过我这边倒是出现一个哭笑不得的问题，plot图ggplot图与文字和代码分离为两个文件。待我晚上看看如何解决。[s:12]
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-364735">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年10月8日 上午9:54
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-364735">
               14 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-364735 -->
            <div class="even bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-14 user-id-379150 post-364735 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               <img src="http://sdn.geekzu.org/avatar/cdccd546d54980b6c3c4256c21cd8dc7?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               god123
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第13楼 的 zggjtsgzczh：
               <br/>
               你好，我用的是r 3.0.1 RStudio-0.97.551.exe
              </p>
              <p>
               从lyx导出rnw后，有了\usepackage{fontspec}  然后报错
               <br/>
               不知怎么设置还是缺少什么
               <br/>
               Error: running ‘texi2dvi’ on ‘ASDF.tex’ failed
              </p>
              <p>
               LaTeX errors:
               <br/>
               !
               <br/>
               ! The fontspec package requires either XeTeX or LuaTeX to function.
               <br/>
               ! The fontspec package requires either XeTeX or LuaTeX to function.
               <br/>
               !
               <br/>
               !
               <br/>
               ! You must change your typesetting engine to, e.g., “xelatex” or “lualatex”
               <br/>
               ! You must change your typesetting engine to, e.g., “xelatex” or “lualatex”
               <br/>
               ! instead of plain “latex” or “pdflatex”.
               <br/>
               ! instead of plain “latex” or “pdflatex”.
               <br/>
               !
               <br/>
               !
               <br/>
               ! See the fontspec documentation for further information.
               <br/>
               ! See the fontspec documentation for further information.
               <br/>
               !
               <br/>
               !
               <br/>
               ! For immediate help type H &lt;return&gt;
               <br/>
               ! For immediate help type H &lt;return&gt;
               <br/>
               |”””””””””””””””””””””””’
               <br/>
               | This is a fatal error: LaTeX will abort
               <br/>
               |………………………………………..
              </p>
              <p>
               In addition: Warning message:
               <br/>
               running command ‘”D:\PROGRA~1\CTEX\MiKTeX\miktex\bin\texi2dvi.exe” –quiet –pdf “ASDF.tex”  -I “D:/setup/R/share/texmf/tex/latex” -I “D:/setup/R/share/texmf/bibtex/bst”‘ had status 1
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
            <div class="bbp-reply-header" id="post-364736">
             <div class="bbp-meta">
              <span class="bbp-reply-post-date">
               2013年10月8日 上午9:57
              </span>
              <a class="bbp-reply-permalink" href="http://cos.name/cn/topic/109287/#post-364736">
               15 楼
              </a>
              <span class="bbp-admin-links">
              </span>
             </div>
             <!-- .bbp-meta -->
            </div>
            <!-- #post-364736 -->
            <div class="odd bbp-parent-forum-999 bbp-parent-topic-109287 bbp-reply-position-15 user-id-379150 post-364736 reply type-reply status-publish hentry">
             <div class="bbp-reply-author">
              <a class="bbp-author-avatar" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               <img src="http://sdn.geekzu.org/avatar/cdccd546d54980b6c3c4256c21cd8dc7?s=80&amp;d=monsterid&amp;r=g"/>
              </a>
              <br/>
              <a class="bbp-author-name" href="http://cos.name/cn/profile/379150/" rel="nofollow" title="查看god123的档案">
               god123
              </a>
              <br/>
              <div class="bbp-author-role">
               普通会员
              </div>
             </div>
             <!-- .bbp-reply-author -->
             <div class="bbp-reply-content">
              <p>
               回复 第13楼 的 zggjtsgzczh：
               <br/>
               能不能留个联系方式，我的邮箱是freelife213@126.com
              </p>
             </div>
             <!-- .bbp-reply-content -->
            </div>
            <!-- .reply -->
           </li>
           <!-- .bbp-body -->
           <li class="bbp-footer">
            <div class="bbp-reply-author">
             作者
            </div>
            <div class="bbp-reply-content">
             帖子
            </div>
            <!-- .bbp-reply-content -->
           </li>
           <!-- .bbp-footer -->
          </ul>
          <!-- #topic-109287-replies -->
          <div class="bbp-pagination">
           <div class="bbp-pagination-count">
            查看 15 个帖子 - 1 到 15（总计 28 个）
           </div>
           <div class="bbp-pagination-links">
            <span class="page-numbers current">
             1
            </span>
            <a class="page-numbers" href="http://cos.name/cn/topic/109287/page/2/">
             2
            </a>
            <a class="next page-numbers" href="http://cos.name/cn/topic/109287/page/2/">
             →
            </a>
           </div>
          </div>
          <div class="bbp-no-reply" id="no-reply-109287">
           <div class="bbp-template-notice">
            <p>
             您必须先登录才能回复该主题。
            </p>
           </div>
          </div>
         </div>
        </div>
        <!-- .entry-content -->
        <footer class="entry-meta">
        </footer>
        <!-- .entry-meta -->
       </article>
       <!-- #post -->
       <div class="comments-area" id="comments">
       </div>
       <!-- #comments -->
      </div>
      <!-- #content -->
     </div>
     <!-- #primary -->
     <div class="sidebar-container" id="tertiary" role="complementary">
      <div class="sidebar-inner">
       <div class="widget-area">
        <aside class="widget bbp_widget_login" id="bbp_login_widget-2">
         <h3 class="widget-title">
          登录
         </h3>
         <form action="http://cos.name/cn/wp-login.php" class="bbp-login-form" method="post">
          <fieldset>
           <legend>
            登录
           </legend>
           <div class="bbp-username">
            <label for="user_login">
             用户名:
            </label>
           </div>
           <div class="bbp-password">
            <label for="user_pass">
             密码:
            </label>
           </div>
           <div class="bbp-remember-me">
            <label for="rememberme">
             记住用户名
            </label>
           </div>
           <div class="bbp-submit-wrapper">
            <button class="button submit user-submit" id="user-submit" name="user-submit" tabindex="104" type="submit">
             登录
            </button>
           </div>
           <div class="bbp-login-links">
            <a class="bbp-register-link" href="http://cos.name/cn/wp-login.php?action=register" title="注册">
             注册
            </a>
            <a class="bbp-lostpass-link" href="http://cos.name/cn/wp-login.php?action=lostpassword" title="忘记密码">
             忘记密码
            </a>
           </div>
          </fieldset>
         </form>
        </aside>
        <aside class="widget widget_text" id="text-7">
         <h3 class="widget-title">
          搜索
         </h3>
         <div class="textwidget">
          <form action="http://www.google.com/search" id="bbp-search-form" method="get" onsubmit="Gsitesearch(this)" role="search">
           <div>
           </div>
          </form>
          <form id="bbp-search-form-baidu" onsubmit="g(this)" role="search">
           <div>
           </div>
          </form>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-2">
         <h3 class="widget-title">
          新鲜事
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            <a href="http://cos.name/cn/topics/">
             最新帖子
            </a>
           </li>
           <li>
            <a href="http://cos.name/cn/view/popular/">
             最热门主题
            </a>
           </li>
           <li>
            <a href="http://cos.name/cn/view/no-replies/">
             消灭零回复
            </a>
           </li>
          </ul>
         </div>
        </aside>
        <aside class="widget widget_text" id="text-3">
         <h3 class="widget-title">
          RSS订阅
         </h3>
         <div class="textwidget">
          <ul>
           <li>
            <img src="http://cos.name/wp-includes/images/rss.png"/>
            <a href="http://cos.name/cn/topics/feed/">
             所有主题
            </a>
           </li>
           <li>
            <img src="http://cos.name/wp-includes/images/rss.png"/>
            <a href="http://cos.name/cn/forums/feed/">
             所有帖子
            </a>
           </li>
          </ul>
         </div>
        </aside>
       </div>
       <!-- .widget-area -->
      </div>
      <!-- .sidebar-inner -->
     </div>
     <!-- #tertiary -->
    </div>
    <!-- #main -->
    <footer class="site-footer" id="colophon" role="contentinfo">
     <div class="site-info">
      版权所有 © 2014 统计之都 | 由
      <a href="http://wordpress.org/">
       WordPress
      </a>
      构建 | 主题修改自
      <a href="http://wordpress.org/themes/twentythirteen">
       Twenty Thirteen
      </a>
     </div>
     <!-- .site-info -->
    </footer>
    <!-- #colophon -->
   </div>
   <!-- #page -->
  </div>
 </body>
</html>